package design.dynamic;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 动态代理
 */
public class DynamicProxyLawyer implements InvocationHandler {

    private Object subject;

    public DynamicProxyLawyer(Object subject){
        this.subject = subject;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        method.invoke(subject,args);
        after();
        return null;
    }

    private void before(){
        System.out.println("签合同");
    }

    private void after(){
        System.out.println("收佣金");
    }
}
